package org.rc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.rc.dto.SxjPageDto;
import org.rc.entity.Sxj;
import org.rc.mapper.SxjMapper;
import org.rc.service.SxjService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class SxjServiceImpl  extends ServiceImpl<SxjMapper, Sxj> implements SxjService {
    @Override
    public void addSxj(Sxj sxj) {
        this.save(sxj);
    }

    @Override
    public Page<Sxj> getSxjPage(SxjPageDto sxjPageDto) {
        Page<Sxj> page = new Page<>(sxjPageDto.getPageNo(),sxjPageDto.getPageSize());
        QueryWrapper<Sxj> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(sxjPageDto.getName()),"name",sxjPageDto.getName());
        return this.baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public void updateSxj(Sxj sxj) {
        this.updateById(sxj);
    }

    @Override
    public void deleteSxj(Long id) {
        this.removeById(id);
    }

    @Override
    public void batchDeleteSxj(List<Long> ids) {
        this.removeByIds(ids);
    }

    @Override
    public List<Sxj> getAllSxj() {
        return list();
    }

    @Override
    public List<Sxj> getSxjsByIds(List<Long> ids) {
        QueryWrapper<Sxj> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",ids);
        return list(queryWrapper);
    }
}
